<template>
  <el-dialog
    title="添加常用意见"
    v-bind="$attrs"
    width="20%"
    :append-to-body="true"
    :modal-append-to-body="true"
    :modal="true"
    :close-on-click-modal="false"
    v-on="$listeners"
  >
    <el-input v-model="opinion" class="pms-textarea" type="textarea" :rows="4" maxlength="500"/>
    <div slot="footer">
      <el-button class="pms-button" @click="cancel">取 消</el-button>
      <el-button class="pms-button-primary" @click="save">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import { insertCommonOpinion } from '@/api/workFlow'
    export default {
        name: 'AddOpinion',
        data() {
            return {
                opinion: ''
            }
        },
        methods: {
            save() {
                if (this.opinion.length <= 0) {
                    return
                }
                insertCommonOpinion(this.opinion).then(res => {
                    if (+res.code === 200) {
                        this.$message.success('添加成功！')
                        this.$emit('addSuccess')
                        this.$emit('update:visible', false)
                    } else {
                        this.$message.error('添加失败！')
                    }
                })
            },
            cancel() {
                this.$emit('update:visible', false)
            }
        }
    }
</script>

<style scoped>

</style>
